import Vue from 'vue'
import Router from 'vue-router'
import layout from '@/view/layout'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router)

let routes = [
	{
		path: '*',
		name: 'NoPage',
		meta: {
			icon: '',
			hide: true,
		},
		component: () => import(/* webpackChunkName: "404" */ '@/view/404/404'),
	},
	{
		path: '/redirect',
		component: layout,
		hidden: true,
		children: [
			{
				path: '/redirect/:path(.*)',
				component: () =>
					import(/* webpackChunkName: "redirect" */ '@/view/redirect/index'),
			},
		],
	},
	{
		path: '/login',
		name: 'Login',
		meta: {
			icon: '',
			hide: true,
		},
		component: () =>
			import(/* webpackChunkName: "Login" */ '@/view/login/index'),
	},
	{
		path: '/',
		component: layout,
		name: 'layout',
		redirect: '/welcome',
		children: [
			{
				path: 'welcome',
				name: 'Welcome',
				meta: {
					icon: '',
					hide: true,
				},
				component: () =>
					import(
						/* webpackChunkName: "welcome" */
						'@/view/welcome/index'
					),
			},
		],
	},
]

let createRouter = () =>
	new Router({
		mode: 'history',
		routes: routes,
	})

const router = createRouter()

export default router
